package com.my.swas.sso;

import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @Description:
 * @author: :MaYong
 */
@SpringBootApplication
@MapperScan(basePackages = "com.my.swas.sso.module.*.mapper")
/**而启动类的扫描默认是扫描与该启动类同包以及其子包下的类，有时候我们还需要修改或者说是添加自动扫描的包的位置，接下来就通过一个简单的例子来讲解如何实现**/
@ComponentScan(basePackages = "com.my.swas")
@EnableCaching
@EnableConfigurationProperties
/*@EnableDiscoveryClient*/
public class SsoApplication {
    static Logger log = LoggerFactory.getLogger(SsoApplication.class);

    public static void main(String[] args) throws UnknownHostException {
        SpringApplication app = new SpringApplication(SsoApplication.class);
        Environment env = app.run(args).getEnvironment();
        String protocol = "http";
        if (env.getProperty("server.ssl.key-store") != null) {
            protocol = "https";
        }
        log.info("\n----------------------------------------------------------\n\t" +
                        "Application '{}' is running! Access URLs:\n\t" +
                        "Local: \t\t{}://localhost:{}{}/\n\t" +
                        "External: \t{}://{}:{}{}/\n\t" +
                        "Swagger: \t{}://localhost:{}{}/doc.html\n\t" +
                        "Profile(s): \t{}\n----------------------------------------------------------",
                env.getProperty("spring.application.name"),
                protocol,
                env.getProperty("server.port"),
                env.getProperty("server.servlet.context-path") + "/admin",
                protocol,
                InetAddress.getLocalHost().getHostAddress(),
                env.getProperty("server.port"),
                env.getProperty("server.servlet.context-path") + "/admin",
                protocol,
                env.getProperty("server.port"),
                env.getProperty("server.servlet.context-path"),
                env.getActiveProfiles());
    }
}
